package com.jvtd.baseProject.app;

import com.jvtd.app.JvtdApplication;
import com.jvtd.baseProject.data.DbManager;
import com.jvtd.baseProject.di.component.DaggerApplicationComponent;
import com.jvtd.baseProject.di.module.NetModule;
import com.jvtd.baseProject.constants.App;
import com.jvtd.baseProject.di.component.ApplicationComponent;
import com.jvtd.baseProject.di.module.ApplicationModule;
import com.squareup.leakcanary.LeakCanary;

import org.litepal.LitePal;

import javax.inject.Inject;

public class MyApplication extends JvtdApplication {
    @Inject
    DbManager mDbManager;
    private ApplicationComponent mApplicationComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule())
                .netModule(new NetModule(App.HTTP_BASE_URL, this))
                .build();

        mApplicationComponent.inject(this);

        //配置开发工具
        configDevelopment();
    }

    /**
     * 全局初始化，onCreate中自动调用
     */
    @Override
    public void configGlobalInit() {
        initDatabase();
    }

    /**
     * 初始化数据库
     */
    private void initDatabase(){
        LitePal.initialize(this);

    }

    public ApplicationComponent getApplicationComponent()
    {
        return mApplicationComponent;
    }


    // TODO: 2018/9/25 开发使用 发布注释
    @Override
    public void configDevelopment() {
        super.configDevelopment();
        if (!LeakCanary.isInAnalyzerProcess(this))
          LeakCanary.install(this);
    }
}
